﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web.Framework.Search;
using System.Collections;
using Web.CrmContacto.Code;
using CrmContacto.Contracts.Contracts.Search;
using CrmContacto.WebApp.App;
using CrmContacto.Contracts.Promociones;

namespace CrmContacto.WebApp.Code.InnerClasses
{
    public class SearchParticipantesObjDataSourceProvider : IGridViewSearchObjectDataSource
    {
        public ReporteParticipantesPosiblesEnPromocion Page { get; set; }

        public WebServiceHelper WebServiceHelper { get; set; }

        //public CustomerSearchParam SearchParam { get; set; }

        public ParticipantesSearchResult SearchResult { get; set; }

        public IList GetObjects()
        {
            return GetObjects(int.MaxValue, 0, string.Empty);
        }

        public IList GetObjects(int maximumRows, int startRowIndex)
        {
            return GetObjects(maximumRows, startRowIndex, string.Empty);
        }

        public IList GetObjects(string sortExpression)
        {
            return GetObjects(int.MaxValue, 0, sortExpression);
        }

        public int TotalNumberOfGetObjects()
        {
            return SearchResult.TotalDeResultados;
        }

        public IList GetObjects(int maximumRows, int startRowIndex, string sortExpression)
        {
            if (WebServiceHelper != null && Page != null && Page.ParticipantesSearch != null)
            {
                //Page.ParticipantesSearch.PageSize = maximumRows;
                Page.ParticipantesSearch.PageSkip = startRowIndex;

                Page.ParticipantesSearch.SortingField = sortExpression;
                if (String.IsNullOrEmpty(Page.ParticipantesSearch.SortingField))
                {
                    Page.ParticipantesSearch.SortingField = "Id";
                    Page.ParticipantesSearch.SortIsAsc = true;
                }

                SearchResult = WebServiceHelper.GetParticipantes(Page.ParticipantesSearch);
                return SearchResult.Resultados;
            }
            else
            {
                SearchResult = new ParticipantesSearchResult();
                return new List<int>(); //Devuelvo una lista vacía
            }            
        }
    }
}